import { Link } from "@heroui/link";
import { Snippet } from "@heroui/snippet";
import { Code } from "@heroui/code";
import { button as buttonStyles } from "@heroui/theme";

import { siteConfig } from "@/config/site";
import { title, subtitle } from "@/components/primitives";
import { GithubIcon } from "@/components/icons";
import wp8 from '/public/images/wp8.png'
import { Image } from "@heroui/image";
import MySub from "../../components/MySub";
import { AiOutlineBell } from "react-icons/ai";
import { BiSolidCalendarHeart } from "react-icons/bi";
import MyCard from "./MyCard";
import MySearch from "@/components/my-search";
import { MyResponse, request } from "@/lib/request";

import type { Metadata } from 'next';

export const revalidate = 60; // 每1小时重新验证一次

export async function generateMetadata(): Promise<Metadata> {
  const description = `夸克4K为您提供丰富的短剧资源、擦边短剧、热门短剧视频和精彩短剧剧情，涵盖短剧大全、影视、音乐、有声资源等高质量内容。免费下载短剧、游戏、软件工具、教程、电子书、杂志和素材模板，满足各类需求，轻松获取优质资源分享。`;
  return {
    // 页面标题
    title: siteConfig.name,
    // 页面描述
    description: description,
    keywords: siteConfig.keywords, // 将关键词连接为一个字符串
    // Open Graph 元数据
    openGraph: {
      title: siteConfig.name,
      description: description,
      type: 'article', // 或 'video.movie'
      images: [
        {
          url: "/images/Open1200.png",
          width: 1200,
          height: 630,
          alt: siteConfig.name,
        },
      ],
      section: '短剧',
      url: `${siteConfig.url}/`
    },
    // Twitter 卡片信息
    twitter: {
      card: 'summary_large_image',
      title: siteConfig.name,
      description: description,
      images: [
        {
          url: "/images/Open1200.png",
          width: 1200,
          height: 630,
          alt: siteConfig.name,
        },
      ],
      site: siteConfig.twitter.site,  // 网站的官方 Twitter 账号
      creator: siteConfig.twitter.creator,  // 内容创作者的 Twitter 账号
    },
    // 其他 SEO 配置
    robots: {
      index: true,
      follow: true,
    },
    alternates: {
      canonical: `${siteConfig.url}/`
    }
  };
}

export default async function Home() {
  const data = (await request<MyResponse>('/queryList', "GET", {}, {
    next: { revalidate: 60 }
  }))?.data
  const hotList = (await request<MyResponse>('/queryHotList', "GET", {}, {
    next: { revalidate: 60 }
  }))?.data

  const keyNmaeWords = [
    "娇妻", "阿姨", "夫人", "女友", "老婆", "前妻", "千金", "公主", "宠妻", "女王", "女神", "甜妻",
    "都市", "穿越", "隐龙", "绝世", "战神", "归来", "至尊", "神医", "总裁", "首富", "亿万", "少爷",
    "王爷", "大佬", "神豪", "天尊", "狂少", "老公", "逆袭", "保安", "赘婿", "离婚", "闪婚", "爱恨",
    "老师", "前夫", "龙帅", "萌宝", "婿", "丐", "虐", "傻", "龙", "总", "婚", "兵", "医"
  ];
  const colors = ["foreground", "primary", "secondary", "success", "warning", "danger"];
  return (
    <section className="flex flex-col gap-4 py-8 md:py-10">

      <MySearch isH1={true} />
      {/* 公告 */}
      <div className="bg-white p-4 flex flex-col gap-3">
        <div className="flex flex-row items-center">
          <div className="whitespace-nowrap flex flex-row  justify-start">
            <AiOutlineBell size={22} />
            <span>【公告】</span>
          </div>
          {/* 「资源库|短剧贴吧|分享群①」https://pan.quark.cn/g/e131e9acb2 */}
          <Link color="primary" underline="always" target="_blank" href="https://pan.quark.cn/g/e131e9acb2">
            +加入夸克免费资源①群[500人]
          </Link>
        </div>
        {/* <div className="flex flex-row items-center">
          <AiOutlineBell size={22} />
          <span>【公告】</span>
          <Link color="danger" underline="always" href="#">
            完整资源库点击查看
          </Link>
        </div> */}
      </div>
      {/*  癖好热词： */}
      <div className="bg-white p-4">
        <div>
          <span className="text-red-500"><BiSolidCalendarHeart className="inline mb-1" size={22} /> 癖好热词：</span>
          {
            keyNmaeWords.map((keyword, index) => {
              const color: any = colors[index % colors.length]; // 依次循环匹配颜色
              const name = encodeURIComponent(`${keyword}`)
              return (
                <Link key={keyword + color} isBlock color={color} href={`/search/${name}`}>
                  {keyword}
                </Link>
              );
            })
          }
        </div>
      </div>
      {/* 热门搜索 */}
      <div>
        <MyCard hotList={hotList} data={data} />
      </div>

      {/* <div className="inline-block max-w-xl text-center justify-center">
        <span className={title()}>Make&nbsp;</span>
        <span className={title({ color: "violet" })}>beautiful&nbsp;</span>
        <br />
        <span className={title()}>
          websites regardless of your design experience.
        </span>
        <div className={subtitle({ class: "mt-4" })}>
          Beautiful, fast and modern React UI library.
        </div>
      </div>

      <div className="flex gap-3">
        <Link
          isExternal
          className={buttonStyles({
            color: "primary",
            radius: "full",
            variant: "shadow",
          })}
          href={siteConfig.links.docs}
        >
          Documentation
        </Link>
        <Link
          isExternal
          className={buttonStyles({ variant: "bordered", radius: "full" })}
          href={siteConfig.links.github}
        >
          <GithubIcon size={20} />
          GitHub
        </Link>
      </div>

      <div className="mt-8">
        <Snippet hideCopyButton hideSymbol variant="bordered">
          <span>
            Get started by editing <Code color="primary">app/page.tsx</Code>
          </span>
        </Snippet>
      </div> */}
    </section>
  );
}
